<template>
  <div class="app-container">
    <div>
      <parser :table-info="tableInfoDatat" :form-info="formConf" :dict-ex="dictEx"></parser>
    </div>
  </div>
</template>

<script>
import Parser from '@/views/bpm/table/Parser'
import { getForm } from '@/api/bpm/table'
import bus from '@/api/eventBus.js'
import { decodeFields } from '@/utils/formGenerator'
import { getDicts } from '@/api/system/dict/data'
export default {
  name: 'showTable',
  components: {
    Parser
  },
  data() {
    return {
      dictEx: {},
      tableInfoDatat: {},
      formConf: {},
      opTabel: [],

      drawingList: []
    }
  },
  created() {
    const formId = this.$route.query && this.$route.query.formId

    if (formId) {
      getForm(formId).then((response) => {
        const data = response.data
        bus.$emit('formId', response.data.formId)
        this.formConf = JSON.parse(data.conf)
        this.drawingList = decodeFields(data.fields)
        this.tableInfoDatat = this.drawingList[0]

        var len = this.tableInfoDatat.children.length
        for (let index = 0; index < len; index++) {
          if (this.tableInfoDatat.children[index].__config__.dict != '') {
            getDicts(this.tableInfoDatat.children[index].__config__.dict).then((response) => {
              var dictOne = {}
              for (let index = 0; index < response.data.length; index++) {
                dictOne[response.data[index].dictValue] = [response.data[index].dictLabel, response.data[index].listClass]
              }
              this.dictEx[response.data[0].dictType] = dictOne
            })
          }
        }

        for (var index in this.tableInfoDatat.children) {
          if (this.tableInfoDatat.children[index].show) {
            this.opTabel = [...this.opTabel, this.tableInfoDatat.children[index].label]
          }
        }
        bus.$emit('tablename', this.tableInfoDatat.tableName)
      })
    } else {
    }
  }
}
</script>

<style></style>
